﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TimbreRecognition.Recognition.Model
{
    public class Neuron : AbstractNeuron
    {

        public readonly static double A = 1;

        private double bias = 0;

        private double[] deltas;

        private double error;

        public Neuron() { }

        public double getBias()
        {
            return bias;
        }

        public void setBias(double bias)
        {
            this.bias = bias;
        }

        public override void setWeights(double[] weights)
        {
            base.setWeights(weights);
            this.deltas = new double[weights.Length];
        }

        public double[] getDeltas()
        {
            return deltas;
        }

        public void setDeltas(double[] deltas)
        {
            this.deltas = deltas;
        }

        public double getError()
        {
            return error;
        }

        public void setError(double error)
        {
            this.error = error;
        }

        public override void recalculateOutput(double[] input)
        {
            double total = getTotalWeight(input);
            double output = activator(total);
            setOutput(output);
        }

        private double activator(double value)
        {
            return 1 / (1 + Math.Exp(-A * value));
        }

        private double getTotalWeight(double[] input)
        {
            double total = 0;
            double[] weights = getWeights();
            for (int i = 0; i < input.Length; i++)
            {
                total += input[i] * weights[i];
            }
            return bias + total;
        }
    }
}
